/*************************************************************************
 * File Name:    Container_With_Most_Water.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: 2013/11/9 12:09:01
 * 
 * Description:  
 |------------------------------------------------------------------------
 | Problem: Container With Most Water
 | Given n non-negative integers a1, a2, ..., an, where each represents a point
 | at coordinate (i, ai). n vertical lines are drawn such that the two endpoints
 | of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis
 | forms a container, such that the container contains the most water.
 |
 | Note: You may not slant the container.
 |------------------------------------------------------------------------
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>

using namespace std;

class Solution {
public:
    int maxArea(vector<int> &height)
    {
        int N = height.size();
        int ans = 0;
        
        int left, right, h;
        
        left = 0, right = N - 1;
        while (left < right) {
            h = min(height[left], height[right]);
            ans = max(ans, h * (right - left));
            
            if (height[left] < height[right]) ++left;
            else --right;
        }
        return ans;
    }
};

int
main(int argc, char *argv[])
{
    vector<int> height;

    height.push_back(1);
    height.push_back(2);
    height.push_back(1);

    Solution sol;

    cout << sol.maxArea(height) << endl;

    return 0;
}
